package com.zhyt.intelligentpipeline.controller;

import com.zhyt.intelligentpipeline.model.CorrosionDetection;
import com.zhyt.intelligentpipeline.model.CrackEvaluateModel;
import com.zhyt.intelligentpipeline.model.FailureSafetyPressure;
import com.zhyt.intelligentpipeline.model.ResidualStrength;
import com.zhyt.intelligentpipeline.service.WorkingConditionService;
import com.zhyt.intelligentpipeline.vo.CrackEvaluateResult;
import com.zhyt.intelligentpipeline.vo.ResidualStrengthResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Para
 * description 工况中需要的接口
 * */
@RequestMapping("workingCondition")
@RestController
public class WorkingConditionController {


    @Resource
    private WorkingConditionService workingConditionService;

    /**
     * 获取安全失效压力
     *
     * */
    @PostMapping("corrosionStrength")
    public ResidualStrengthResult getCorrosionStrength(@RequestBody ResidualStrength residualStrength){
        return ResidualStrengthResult.getInstance(residualStrength);
    }



    @GetMapping("/pipeline/initialStation/{initialStation}/endStation/{endStation}/corrosion")
    public List<CorrosionDetection> getPipelineCorrosion(@PathVariable(value = "initialStation")String initialStation,
                                                         @PathVariable(value = "endStation")String endStation){
        return workingConditionService.getPipelineCorrosionInfo(initialStation,endStation);
    }

    @PostMapping("crackState")
    public CrackEvaluateResult getCrackState(@RequestBody CrackEvaluateModel crackEvaluateModel){

        return CrackEvaluateResult.getCrackEvaluateResult(crackEvaluateModel);
    }

    /**
     * 传入管段ID来获取获取预测值
     * */
    @PostMapping("ids/f1/{f1}/f2/{f2}/corrosionStrength/")
    public List<FailureSafetyPressure> getFailureSafetyPressureByIds(@RequestBody List<String> ids,
                                                                     @PathVariable(value = "f1")Double f1,
                                                                     @PathVariable(value = "f2")Double f2){
        List<FailureSafetyPressure> failureSafetyPressures = new ArrayList<>();
        for (String id : ids) {
            FailureSafetyPressure failureSafetyPressureByCorId = workingConditionService.getFailureSafetyPressureByCorId(id);
            if(failureSafetyPressureByCorId == null){
                FailureSafetyPressure failureSafetyPressure = workingConditionService.getFailureSafetyPressure(id, f1, f2);
                failureSafetyPressures.add(failureSafetyPressure);
            }else{
                FailureSafetyPressure failureSafetyPressureByCorId1 = workingConditionService.getFailureSafetyPressureByCorId(id);
                failureSafetyPressures.add(failureSafetyPressureByCorId1);
            }
        }
        return failureSafetyPressures;
    }
}
